<%@ page language="java" contentType="text/html" pageEncoding="utf-8"%>
<%@include file="/WEB-INF/pages/common/common.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@include file="/WEB-INF/pages/common/head.jsp"%>
<title><spring:message code="title.dictionary" /></title>
<script type="text/javascript">
	var datagrid;
	var message = $.messager;
	var operateDialog;
	$(function() {
		datagrid = $('#datagrid').datagrid({
			url : '${path}/business/supplier_quality/env_manage/ajaxList.do',
			onLoadSuccess : function() {
				datagrid.datagrid('clearSelections');
			}
		});
	});
	//子页面返回方法
	function returnResult() {
		operateDialog.dialog('close');
		datagrid.datagrid('unselectAll');
		datagrid.datagrid('reload');
	}
	//判断选择单据是否是一条
	function isChooseOne(rows) {
		var flag = false;
		if (rows.length > 1) {
			message
					.show({
						msg : "<spring:message code='msg.choose' arguments='"+rows.length+"'/>",
						title : '<spring:message code='msg.tip'/>'
					});
			flag = false;
		} else if (rows.length == 0) {
			message.show({
				msg : "<spring:message code='msg.please.choose'/>",
				title : '<spring:message code='msg.tip'/>'
			});
			flag = false;
		} else {
			flag = true;
		}
		return flag;
	}
	function search_() {
		datagrid.datagrid('unselectAll');
		datagrid.datagrid('load', imonJYRH.serializeObject($("#tableForm *")));
	}
	function reset_() {
		$("#tableForm *").each(function() {
			$(":input:not(:checkbox,:radio)", this).val("");
		});
	}
	function modify_() {
		var rows = datagrid.datagrid("getSelections");
		if (!isChooseOne(rows)) {
			return;
		}
		var href = '${path}/business/supplier_quality/env_manage/modifyUI.do?id='
				+ rows[0]['id'];
		operateDialog = $("#operateDialog").dialog({
			title : '<spring:message code='msg.modify'/>',
			width : 1000,
			height : 520
		});
		$("#operateIFrame")[0].src = href;
		operateDialog.dialog('open');
	}

	function add_() {
		var href = '${path}/business/supplier_quality/env_manage/addUI.do';
		operateDialog = $("#operateDialog").dialog({
			title : '<spring:message code='msg.create'/>',
			width : 1000,
			height : 520
		});
		$("#operateIFrame")[0].src = href;
		operateDialog.dialog('open');
	}

	function delete_() {
		var ids = getSelectedIds();

		$.messager
				.confirm(
						'<spring:message code='msg'/>',
						'<spring:message code='msg.confirm.delete'/>',
						function(r) {
							if (r && null != ids) {
								imonJYRH.showZone();
								$
										.ajax({
											url : imonJYRH
													.url("${path}/business/supplier_quality/env_manage/ajaxDelete.do"),
											cache : false,
											data : {
												'ids' : ids.join(',')
											},
											success : function(reMsg) {
												if (reMsg.success) {
													search_();
													message
															.show({
																msg : reMsg.msg,
																title : '<spring:message code='msg.tip'/>',
																showType : 'slide'
															});
												} else {
													message
															.alert(
																	'<spring:message code='msg.tip'/>',
																	reMsg.msg);
												}
												imonJYRH.hideZone();
											}
										});
							}
						});
	}

	function getSelectedIds() {
		var rows = datagrid.datagrid("getSelections");
		if (rows.length > 0) {
			var ids = [];
			for ( var i = 0; i < rows.length; i++) {
				ids.push(rows[i].id);
			}
			return ids;
		} else {
			$.messager.alert('<spring:message code='msg.error'/>',
					'<spring:message code='msg.delete'/>', 'error');
			return null;
		}
	}
	/**
	 *环境体系导出
	 */
		function export_() {
		  var rows = datagrid.datagrid("getSelections");
 	    var id ="";
         if (rows.length > 0) {
         	if(rows.length==1){
                  for ( var i = 0; i < rows.length; i++) {
                      id=rows[i].id;
                  }
                  $.messager.confirm('提示', '确定导出数据？', function(r) {
      				if (r&&id!=null) {
      					var url = "${path}/excel/envManageExcel/exportExcel.do";
      					url += "?id=" + id;
      					$("#env_manageForm").attr("action", url).submit();
      				} else {
      					return;
      				}
      			});
         	}else{
         		$.messager.alert('<spring:message code='msg.error'/>','请选择一项进行导出','error');
         		return
         	}
         }else{
             $.messager.alert('<spring:message code='msg.error'/>','请选择','error');
             return;
         }
	}
	  function dialogSupplier_(){
            var href = '${path}/basedata/supplier/dialogUI.do';
            operateDialog = $("#operateDialog").dialog({
                title : '<spring:message code='msg.dialog.choose'/>',
                width : 650,
                height : 400
            });
            $("#operateIFrame")[0].src=href;
            operateDialog.dialog('open');
        }
     function dialogSupplierReturn(row){
            $("#supplierId").val(row['id']);
            $("#supplierCode").val(row['code']);
            $("#supplierName").val(row['name']);
            operateDialog.dialog('close');
        }
 	/**
 	 *发送邮件
 	 */
 	function sendMail() {
 		var rows = datagrid.datagrid("getRows");
           if (rows.length > 0) {
                    $.messager.confirm('提示', '确定向供应商发送邮件？', function(r) {
        				if (r) {
        			      imonJYRH.showZone();
                       $.ajax({
                           url : imonJYRH.url("${path}/excel/envManageExcel/ajaxSendMail.do"),
                           cache : false,
                           success : function(reMsg) {
                               if(reMsg.success){
                                   message.show({
                                       msg : reMsg.msg,
                                       title : '发送成功',
                                       showType:'slide'
                                   });
                               }else{
                                   message.alert('<spring:message code='msg.tip'/>',reMsg.msg);
                               }
                               imonJYRH.hideZone();
                           }
                       });
        				} else {
        					return;
        				}
        			});
           }else{
               $.messager.alert('<spring:message code='msg.error'/>','没有数据','error');
               return;
           }
 	}
</script>
</head>
<body class="easyui-layout">
	<form id="env_manageForm"  
		method="post">
		<div data-options="region:'north'" style="overflow: hidden;">
			<div class="datagrid-toolbar" style="height:auto;">
				<br />
				<fieldset>
					<table width="100%" id="tableForm">
						<tr>
							<td align="right">SupplierCode供应商编码：</td>
							<td>  <input type="hidden" id='supplierId' name="supplierId"/>
                              <input type="text" id="supplierCode" onclick="dialogSupplier_();" readonly="true"/>
							</td>
							<td align="right">SupplierName供应商名称：</td>
							<td> <input type="text" id="supplierName" style="width: 180px;" disabled/>
							</td>
							<!-- <td align="right">Supplier Type供应商类型：</td>
                    <td>
                        <input type="text"  name="type" disabled/>
                    </td>-->
                </tr>
            </table>
        </fieldset>
    </div>
</div>
<div data-options="region:'center'">
    <div id="tb">
        <a class="easyui-linkbutton" href="javascript:void(0);" plain="true" iconCls="icon-search" onclick="search_();"><spring:message code="bar.command.search"/></a>
        <a class="easyui-linkbutton" href="javascript:void(0);" plain="true" iconCls="icon-undo" onclick="reset_();"><spring:message code="bar.command.reset"/></a>
        <a class="easyui-linkbutton" href="javascript:void(0);" plain="true" iconCls="icon-add" onclick="add_();">Add新增</a>
        <a class="easyui-linkbutton" href="javascript:void(0);" plain="true" iconCls="icon-edit" onclick="modify_();"_>Modify修改</a>
        <a class="easyui-linkbutton" href="javascript:void(0);" plain="true" iconCls="icon-cancel" onclick="delete_();"><spring:message code="bar.command.delete"/></a>
        <!--<a class="easyui-linkbutton" href="javascript:void(0);" plain="true" iconCls="icon-import">Import导入</a>-->
        <a class="easyui-linkbutton" href="javascript:void(0);" plain="true" iconCls="icon-export" onclick="export_();">Export导出</a>
        <a class="easyui-linkbutton" href="javascript:void(0);" plain="true" iconCls="icon-mail" onclick="sendMail();">向证书过期的供应商发送邮件</a>
    </div>
    <table class="easyui-datagrid" toolbar="#tb" pagination="true" fit="true" nowrap="false" id="datagrid">
        <thead>
        <tr>
            <th field="ck" checkbox="true"></th>
            <th field="supplierCode" width="80" align="center">SupplierCode<br/>供应商编码</th>
            <th field="supplierName" width="100" align="center">SupplierName<br/>供应商名称</th>
            <th field="value" width="100" align="center">EvaluationValue<br/>得分</th>
            <th field="certificationType" width="150" align="center">certificationType<br/>认证类型</th>
            <th field="certificationDates" width="120" align="center">CertificationDate<br/>认证日期</th>
            <th field="expiredDates" width="100" align="center">ExpiredDate<br/>到期日期</th>
            <th field="updateRequired" width="100" align="center">UpdateRequired<br/>请求续订</th>
            <th field="comment" width="150" align="center">Comment<br/>评论</th>
            <th field="mailDates" width="80" align="center">MailDate<br/>发送邮件日期</th>
        </tr>
        </thead>
    </table>
</div>
<div id="operateDialog" class="easyui-dialog" style="width:880px;height:520px;"
     data-options="iconCls:'icon-save',resizable:true,modal:true,closed: true,collapsible:true,maximizable:true">
    <iframe scrolling="auto" id='operateIFrame' frameborder="0"  src="" style="width:100%;height:100%;"/>
</div>
						</tr>
					</table>
				</fieldset>
				<br />
			</div>
		</div>
		<div data-options="region:'center'">
			<div id="tb">
				<a class="easyui-linkbutton" href="javascript:void(0);" plain="true"
					iconCls="icon-search" onclick="search_();"><spring:message
						code="bar.command.search" /> </a> <a class="easyui-linkbutton"
					href="javascript:void(0);" plain="true" iconCls="icon-undo"
					onclick="reset_();"><spring:message code="bar.command.reset" />
				</a> <a class="easyui-linkbutton" href="javascript:void(0);"
					plain="true" iconCls="icon-add" onclick="add_();">Add新增</a> <a
					class="easyui-linkbutton" href="javascript:void(0);" plain="true"
					iconCls="icon-edit" onclick="modify_();" _>Modify修改</a> <a
					class="easyui-linkbutton" href="javascript:void(0);" plain="true"
					iconCls="icon-cancel" onclick="delete_();"><spring:message
						code="bar.command.delete" /> </a> <a class="easyui-linkbutton"
					href="javascript:void(0);" plain="true" iconCls="icon-export"
					onclick="export_();"><spring:message code="bar.command.export" />
				</a> <a class="easyui-linkbutton" href="javascript:void(0);"
					plain="true" iconCls="icon-mail">向证书过期的供应商发送邮件</a>
			</div>
			<table class="easyui-datagrid" toolbar="#tb" pagination="true"
				fit="true" nowrap="false" id="datagrid">
				<thead>
					<tr>
						<th field="ck" checkbox="true"></th>
						<th field="supplierCode" width="80" align="center">SupplierCode<br />供应商编码</th>
						<th field="supplierName" width="100" align="center">SupplierName<br />供应商名称</th>
						<th field="value" width="100" align="center">EvaluationValue<br />得分</th>
						<th field="certificationType" width="150" align="center">certificationType<br />认证类型</th>
						<th field="certificationDates" width="120" align="center">CertificationDate<br />认证日期</th>
						<th field="expiredDates" width="100" align="center">ExpiredDate<br />到期日期</th>
						<th field="updateRequired" width="100" align="center">UpdateRequired<br />请求续订</th>
						<th field="comment" width="150" align="center">Comment<br />评论</th>
						<th field="mailDates" width="80" align="center">MailDate<br />发送邮件日期</th>
					</tr>
				</thead>
			</table>
		</div>
	</form>
	<div id="operateDialog" class="easyui-dialog"
		style="width:880px;height:520px;"
		data-options="iconCls:'icon-save',resizable:true,modal:true,closed: true,collapsible:true,maximizable:true">
		<iframe scrolling="auto" id='operateIFrame' frameborder="0" src=""
			style="width:100%;height:100%;" />
	</div>

</body>
</html>
